Use read_csv from pandas to load the data from the data folder and assign it to a variable named gapminder_df.
Contents

from hashlib import sha1
import altair as alt
import pandas as pd
import numpy as np
from hashlib import sha1
alt.data_transformers.disable_max_rows()
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 2
1 from hashlib import sha1
----> 2 import altair as alt
3 import pandas as pd
4 import numpy as np
ModuleNotFoundError: No module named 'altair'
Use read_csv from pandas to load the data from the data folder and assign it to a variable named gapminder_df.#
Make sure to parse any time columns using the parse_dates argument.#
gapminder_df = pd.read_csv("C:/Users/sindi/Downloads/world-data-gapminder.csv", parse_dates=['year'])
gapminder_df.head()
| country | year | population | region | sub_region | income_group | life_expectancy | income | children_per_woman | child_mortality | pop_density | co2_per_capita | years_in_school_men | years_in_school_women | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Afghanistan | 1800-01-01 | 3280000 | Asia | Southern Asia | Low | 28.2 | 603 | 7.0 | 469.0 | NaN | NaN | NaN | NaN |
| 1 | Afghanistan | 1801-01-01 | 3280000 | Asia | Southern Asia | Low | 28.2 | 603 | 7.0 | 469.0 | NaN | NaN | NaN | NaN |
| 2 | Afghanistan | 1802-01-01 | 3280000 | Asia | Southern Asia | Low | 28.2 | 603 | 7.0 | 469.0 | NaN | NaN | NaN | NaN |
| 3 | Afghanistan | 1803-01-01 | 3280000 | Asia | Southern Asia | Low | 28.2 | 603 | 7.0 | 469.0 | NaN | NaN | NaN | NaN |
| 4 | Afghanistan | 1804-01-01 | 3280000 | Asia | Southern Asia | Low | 28.2 | 603 | 7.0 | 469.0 | NaN | NaN | NaN | NaN |
plot_a = alt.Chart(gapminder_df).mark_line().encode(
x='year',
y='population',
color='region').properties(
title='Plot A',width=300, height=200)
plot_b = alt.Chart(gapminder_df).mark_line().encode(
x='year',
y='sum(population)',
color='region').properties(
title='Plot B',width=300, height=200)
plot_c = alt.Chart(gapminder_df).mark_area().encode(
x='year',
y='sum(population)',
color='region').properties(
title='Plot C',width=300, height=200)
plot_d = alt.Chart(gapminder_df).mark_circle().encode(
alt.X('year', scale=alt.Scale(zero=False)),
alt.Y('population'),
alt.Color('region')).properties(
title='Plot D',width=300, height=200)
alt.vconcat(alt.hconcat(
plot_a, plot_b
).resolve_scale(
color='independent'),
alt.hconcat(
plot_c, plot_d
).resolve_scale(
color='independent'))
plot_a